package com.csjy.migration.hnnd.workflow;

import com.csjy.migration.hnnd.*;
import com.csjy.migration.hnnd.annotation.Task;
import com.csjy.migration.hnnd.business.SourceBusinessData;
import com.csjy.migration.hnnd.dict.Office;
import com.fasterxml.jackson.core.JsonProcessingException;

import java.util.*;

/**
 * 项目受理流程业务数据迁移类
 */
public class ItemAcceptHny extends WorkflowMigration {

  public ItemAcceptHny(DbUtil sourceDbUtil, DbUtil targetDbUtil, SourceBusinessData sourceData, ProgramArgument programArgument, String projectId, String procInstId, Map procInstRow) throws Exception {
    super(sourceDbUtil, targetDbUtil, sourceData, programArgument, projectId, procInstId, procInstRow);
    this.customInitData();
  }

  @Override
  public void customInitData() {
    this.curBizType = "xmsl";
  }

  @Override
  public void customInsertOrUpdateData() {

  }

  @Task("项目受理@受理人提交资料")
  public void migrationSlrtjzl() throws Exception {
    this.curModelMap.put("all", new String[]{"exclusiveGateway1552641631956tjsh","提交审核"});
    this.curAffixType = "xmsl";
    this.curAffixTypeCommon = this.curAffixType;
    this.setCommonData(true,null);
    this.curProcessData.put("reason",Tool.replaceBrFlagStr(this.sourceData.getBtItemBasic().get(0).get("MANAGERNOTION")));
    this.curProcessData.put("next_step_user", this.getJbpmVarInstValueByName("AuditMaster"));
    if(this.curNextStepUserIds != null) {
      this.actHiVarinstMap.put("task1540522793884", this.curNextStepUserIds);
    }
  }

  @Task("项目受理@办事处负责人审批")
  public void migrationBscfzrsp() throws Exception {
    this.curModelMap.put("通过", new String[]{"exclusiveGateway1540523162807tg","通过"});
    this.curModelMap.put("不同意", new String[]{"endbty","不同意"});


    this.setCommonData(true,null);

    // 刘三(liusan)||张非(zhangfei)
    String managerAB = this.getJbpmVarInstValueByName("managerAB");
    if(!(managerAB == null || managerAB.equals(""))) {
      String[] managerABArr = managerAB.split("\\|\\|");
      if(managerABArr.length > 0) {
        this.curCustomData.put("managerA", BusinessTool.getEmpCode(managerABArr[0]));
        this.curCustomData.put("isRequestBranchManagerB","0");
        if (managerABArr.length == 2) {
          this.curCustomData.put("managerB", BusinessTool.getEmpCode(managerABArr[1]));
          this.curCustomData.put("isRequestBranchManagerB","1");
        }
      }
    }
  }

  @Task("项目受理@分公司负责人审批")
  public void migrationFgsfzrsp() throws Exception {
    this.curModelMap.put("同意", new String[]{"exclusiveGateway1540523188963tg","通过"});
    this.curModelMap.put("同意受理", new String[]{"exclusiveGateway1540523188963tg","通过"});
    this.curModelMap.put("通过", new String[]{"exclusiveGateway1540523188963tg","通过"});
    this.curModelMap.put("不同意", new String[]{"endbty","不同意"});
    this.setCommonData(true,null);

    // 刘三(liusan)=>liusan
    this.curCustomData.put("managerB",BusinessTool.getEmpCode(this.getJbpmVarInstValueByName("managerB")));
  }

  @Task("项目受理@公司融资部审批")
  public void migrationGsrzbsp() throws Exception {
    this.curModelMap.put("通过", new String[]{"exclusiveGateway1540523222234ty","同意"});
    // 林业项目部
    this.curModelMap.put("同意", new String[]{"exclusiveGateway1540523222234ty","同意"});
    this.curModelMap.put("不同意", new String[]{"endbty","不同意"});
    this.setCommonData(false,null);
    this.curCustomData.put("managerC",BusinessTool.getEmpCode(this.getJbpmVarInstValueByName("managerC")));
  }

  @Task("项目受理@林业项目部审批")
  public void migrationLyxmbsp() throws JsonProcessingException, Exception {
    this.migrationGsrzbsp();
  }

  @Task("项目受理@业务副总经理审批")
  public void migrationYwfzjlsp() throws Exception {
    this.curModelMap.put("同意", new String[]{"task1540522793884ty","同意"});
    this.curModelMap.put("同意受理", new String[]{"task1540522793884ty","同意"});
    this.curModelMap.put("不同意", new String[]{"endbty","不同意"});
    this.setCommonData(false,null);
  }

  @Task("项目受理@A经理出调查协议")
  public void migrationAjlcdcxy() throws Exception {
    this.curModelMap.put("提交指派事务所", new String[]{"task1540522825190zpsws","指派事务所"});
    this.curModelMap.put("不派事务所", new String[]{"task1559006939870bpsws","不派事务所"});
    this.curAffixType = "qzfj";
    this.curAffixTypeCommon = this.curAffixType;
    this.setCommonData(true,null);
    this.curCustomData.put("titlechakan","查看签字附件");
  }

  @Task("项目受理@审计内勤指派事务所")
  public void migrationSjnqzpsws() throws JsonProcessingException, Exception {
    this.curModelMap.put("all", new String[]{"endjs","结束"});
    this.setCommonData(true,null);
    this.curCustomData.put("office", DictTool.getTargetDictCode(Office.class, this.getJbpmVarInstValueByName("accountCorp")));
  }
}
